﻿using CloudFranceTriple.WebRole.Controllers;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;

namespace CloudFranceTriple.Tests.Controllers
{
    [TestClass]
    public class HomeControllerTest : UnitTestBase
    {
        private TestContext ctx;
        public TestContext TestContext { get { return ctx; } set { ctx = value; } }

        [TestMethod]
        [TestCategory("Home")]
        public void HomeController_PollItem()
        {
            // Arrange
            //HomeController controller = new HomeController();
            var controller = new CloudFranceTriple.WebRole.Controllers.HomeController(base.GetWebSecurity.Object);

            controller.ControllerContext = base.GetControllerContext.Object;

            var context =
                new Mock<HttpContextBase>(MockBehavior.Strict);

            controller.Url =
                new UrlHelper(new RequestContext(context.Object,
                new RouteData()), new RouteCollection());

            // Act
            var result = controller.PollItem() as PartialViewResult;

            // Assert :
            Assert.IsNotNull(result);
        }

        [TestMethod]
        [TestCategory("Home")]
        public void HomeController_LastConnected()
        {
            // Arrange
            //HomeController controller = new HomeController();
            var controller = new CloudFranceTriple.WebRole.Controllers.HomeController(base.GetWebSecurity.Object);

            controller.ControllerContext = base.GetControllerContext.Object;

            var context =
                new Mock<HttpContextBase>(MockBehavior.Strict);

            controller.Url =
                new UrlHelper(new RequestContext(context.Object,
                new RouteData()), new RouteCollection());

            // Act
            var result = controller.LastConnected(10) as PartialViewResult;

            // Assert
            Assert.IsNotNull(result);
            if (result == null) return;
            var resultCount = (result.Model as List<String>).Count;
            //Il y a au moins l'utilisateur de test qui est connecté et la demande est limité à 10 noms.
            Assert.IsTrue(resultCount > 0 & resultCount <= 10);
        }

        [TestMethod]
        [TestCategory("Home")]
        public void HomeController_GetTodayBirthday()
        {
            // Arrange
            //HomeController controller = new HomeController();
            var controller = new CloudFranceTriple.WebRole.Controllers.HomeController(base.GetWebSecurity.Object);

            controller.ControllerContext = base.GetControllerContext.Object;

            var context =
                new Mock<HttpContextBase>(MockBehavior.Strict);

            controller.Url =
                new UrlHelper(new RequestContext(context.Object,
                new RouteData()), new RouteCollection());

            // Act
            var result = controller.GetTodayBirthday() as PartialViewResult;

            // Assert
            Assert.IsNotNull(result);
        }

        [TestMethod]
        [TestCategory("Home")]
        public void HomeController_GetNextUserBirthday()
        {
            // Arrange
            //HomeController controller = new HomeController();
            var controller = new CloudFranceTriple.WebRole.Controllers.HomeController(base.GetWebSecurity.Object);

            controller.ControllerContext = base.GetControllerContext.Object;

            var context =
                new Mock<HttpContextBase>(MockBehavior.Strict);

            controller.Url =
                new UrlHelper(new RequestContext(context.Object,
                new RouteData()), new RouteCollection());

            // Act
            var result = controller.GetNextUserBirthday(10) as PartialViewResult;

            // Assert
            Assert.IsNotNull(result);
            if (result == null) return;
        }

        [TestMethod]
        [TestCategory("Home")]
        public void HomeController_ForumTopicItem()
        {
            // Arrange
            //HomeController controller = new HomeController();
            var controller = new CloudFranceTriple.WebRole.Controllers.HomeController(base.GetWebSecurity.Object);

            controller.ControllerContext = base.GetControllerContext.Object;

            var context =
                new Mock<HttpContextBase>(MockBehavior.Strict);

            controller.Url =
                new UrlHelper(new RequestContext(context.Object,
                new RouteData()), new RouteCollection());

            // Act
            var result = controller.ForumTopicItem() as PartialViewResult;

            // Assert
            Assert.IsNotNull(result);
        }

        [TestMethod]
        [TestCategory("Home")]
        public void HomeController_BirthdayItem()
        {
            // Arrange
            //HomeController controller = new HomeController();
            var controller = new CloudFranceTriple.WebRole.Controllers.HomeController(base.GetWebSecurity.Object);

            controller.ControllerContext = base.GetControllerContext.Object;

            var context =
                new Mock<HttpContextBase>(MockBehavior.Strict);

            controller.Url =
                new UrlHelper(new RequestContext(context.Object,
                new RouteData()), new RouteCollection());

            // Act
            var result = controller.BirthdayItem() as PartialViewResult;

            // Assert
            Assert.IsNotNull(result);
        }

        [TestMethod]
        [TestCategory("Home")]
        public void HomeController_Index()
        {

            // Arrange
            //HomeController controller = new HomeController();
            var controller = new CloudFranceTriple.WebRole.Controllers.HomeController(base.GetWebSecurity.Object);

            controller.ControllerContext = base.GetControllerContext.Object;

            var context =
                new Mock<HttpContextBase>(MockBehavior.Strict);

            controller.Url =
                new UrlHelper(new RequestContext(context.Object,
                new RouteData()), new RouteCollection());

            // Act
            var result = controller.Index() as ViewResult;

            // Assert
            Assert.IsNotNull(result);
        }

        [TestMethod]
        [TestCategory("Home")]
        public void HomeController_About()
        {
            // Arrange
            var controller = new HomeController(base.GetWebSecurity.Object);

            controller.ControllerContext = base.GetControllerContext.Object;

            var context =
                new Mock<HttpContextBase>(MockBehavior.Strict);

            controller.Url =
                new UrlHelper(new RequestContext(context.Object,
                new RouteData()), new RouteCollection());

            // Act
            var result = controller.About() as ViewResult;

            // Assert
            Assert.IsNotNull(result);
        }

        [TestMethod]
        [TestCategory("Home")]
        public void HomeController_Contact()
        {
            // Arrange
            var controller = new HomeController(base.GetWebSecurity.Object);

            controller.ControllerContext = base.GetControllerContext.Object;

            var context =
                new Mock<HttpContextBase>(MockBehavior.Strict);

            controller.Url =
                new UrlHelper(new RequestContext(context.Object,
                new RouteData()), new RouteCollection());

            // Act
            var result = controller.Contact() as ViewResult;

            // Assert
            Assert.IsNotNull(result);
        }
    }
}
